﻿using System;
using System.Linq;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.AIModule.Schedulers.InstanceStats
{
    /// <summary>
    /// 实例状态记录
    /// </summary>
    public class StatusMonitorRec : DbBaseEntity
    {
        /// <summary>
        /// 已发现的实例数
        /// </summary>
        public long Instances { get; init; }
        
        /// <summary>
        /// 嘟文总数
        /// </summary>
        public long NotesCount { get; init; }
        
        /// <summary>
        /// 本地嘟文数
        /// </summary>
        public long OriginalNotesCount { get; init; }
        
        /// <summary>
        /// 本地用户数
        /// </summary>
        public long OriginalUsersCount { get; init; }
        
        /// <summary>
        /// 用户总数
        /// </summary>
        public long UsersCount { get; init; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 日期字符串
        /// </summary>
        public string DateStr { get; set; } = DateTime.Now.ToString("yyyyMMdd");
    }

    public static class StatusMonitorRecDA
    {
        public static void Insert(this StatusMonitorRec entity)
        {
            MongoService<StatusMonitorRec>.Insert(entity);
        }

        /// <summary>
        /// 获取最新状态信息
        /// </summary>
        /// <returns></returns>
        public static StatusMonitorRec GetNewest()
        {
            return MongoService<StatusMonitorRec>.Get(p => true, p => p.CreateTime, false, 0, 1).FirstOrDefault();
        }
    }
}